﻿using System;
using System.Drawing;

namespace Maze
{
    public abstract class Enemy
    {
        private Point location;
        protected PathFinder pathFinder;

        public Enemy(Point startSquare, PathFinder pathFinder)
        {
            this.location = MazeForm.SquareToPixels(startSquare);

            this.pathFinder = pathFinder;
        }

        public Point Location
        {
            get
            {
                return this.location;
            }
        }

        public void Update(int divider)
        {
            Point square = this.pathFinder.CurrentPath.First.Value;
            Point point = MazeForm.SquareToPixels(square);

            this.location.X += Math.Sign(point.X - this.location.X) * (MazeForm.SquareSize.Width / divider);
            this.location.Y += Math.Sign(point.Y - this.location.Y) * (MazeForm.SquareSize.Height / divider);

            if (this.location == point)
            {
                this.OnNewSquare(square);
                this.pathFinder.CurrentPath.RemoveFirst();
            }
        }

        protected abstract void OnNewSquare(Point square);
    }
}
